/* Copyright (c) 2009 SpringShowcase, Inc.
 * All right reserved.
 * http://code.google.com/p/springshowcase/
 * This software is the confidential and proprietary information of BeyondWeb
 * , Inc. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement
 * you entered into with BeyondWeb.
 *
 * Revision History
 * Author              Date             Description
 * ------------------   --------------    ------------------
 *  taeki.kim           2010. 4. 2.        
*/
package org.springshowcase.core.commons.utils;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * stream 관련 유틸
 * 기본적으로 org.apache.commons.io.IOUtils 클래스를 상속 받아서 
 * 부모 메서드를 재사용 할 수 있다.
 *  
 * @author kim.tae.ki
 * @version
 * @see
 * 
 * This file contains the declarations of String class and its helper classes.
 */
public class IOStreamUtils extends org.apache.commons.io.IOUtils {

    // ---------------------------------------------------------------------
    // Class Variable Declaration
    // ---------------------------------------------------------------------
    
	/** The Constant log. */
	private static final Logger logger = LoggerFactory
			.getLogger(IOStreamUtils.class);

	// ---------------------------------------------------------------------
    // Constructor Method Declaration
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // DI Method (setter,getter) Declaration
    // ---------------------------------------------------------------------
	
	// ---------------------------------------------------------------------
    // this Method (public/private) Declaration
    // ---------------------------------------------------------------------
	
	/**
	 * Stream toline string array.
	 * 
	 * @param inputStream the input stream
	 * @param encoding the encoding
	 * 
	 * @return the list< string>
	 * 
	 * @throws Exception the exception
	 */
	public static List<String> streamTolineStringArray(InputStream inputStream,
			String encoding) throws Exception {
		LineIterator lit;
		List <String>lineValues;
		
		lit = IOStreamUtils.lineIterator(inputStream, "UTF-8");
		if (lit == null)
			return null;
		
		lineValues = new ArrayList<String>();

		try {
			while (lit.hasNext()) {
				lineValues.add(StringUtils.trimToEmpty(lit.nextLine()));
			}
		} finally {
			LineIterator.closeQuietly(lit);
		}
		return lineValues;
	}
	
	// ---------------------------------------------------------------------
    // interface implement Method (public/private) Declaration
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // abstract implement Method (public/private) Declaration
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // abstract Method (public/private) Declaration
    // ---------------------------------------------------------------------
	
}
